"""
下面的文件将会从csv文件中读取读取短信与电话记录，
你将在以后的课程中了解更多有关读取文件的知识。
"""
import csv

with open('texts.csv', 'r') as f:
    reader = csv.reader(f)
    texts = list(reader)

with open('calls.csv', 'r') as f:
    reader = csv.reader(f)
    calls = list(reader)

"""
任务4:
电话公司希望辨认出可能正在用于进行电话推销的电话号码。
找出所有可能的电话推销员:
这样的电话总是向其他人拨出电话，
但从来不发短信、接收短信或是收到来电


请输出如下内容
"These numbers could be telemarketers: "
<list of numbers>
电话号码不能重复，每行打印一条，按字典顺序排序后输出。
"""

def find_all_callers():
    set_all_callers = set()
    for call in calls:
        set_all_callers.add(call[0])
    return set_all_callers

def remove_all_receivers_from_set_callers(set_all_callers):
    for call in calls:
        if(call[1] in set_all_callers):
            set_all_callers.remove(call[1])

    for text in texts:
        if(text[0] in set_all_callers):
            set_all_callers.remove(text[0])
        if(text[1] in set_all_callers):
            set_all_callers.remove(text[1])

    return set_all_callers

def sort_all_callers(set_all_callers):
    l = []
    for caller in set_all_callers:
        l.append(caller)
    
    l.sort()
    return l

def find_all_telemarketers():
    set_all_callers = find_all_callers()
    set_all_callers = remove_all_receivers_from_set_callers(set_all_callers)
    list_sorted_all_callers = sort_all_callers(set_all_callers)
    ret_txt = ''
    for caller in list_sorted_all_callers:
        ret_txt = ret_txt + '\n' + caller
    
    print('These numbers could be telemarketers: {}'.format(ret_txt))

find_all_telemarketers()